package com.topvision.myviewtest.viewpager;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.topvision.myviewtest.R;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lucy
 * @date 2018-09-20 11:25
 * @description //TODO
 */

public class StateFragment extends Fragment {
    public static final String KEY_BUNDLE = "bundle_key";
    private RecyclerView mRecyclerView;

    public static StateFragment getInstance(int id) {
        StateFragment fragment = new StateFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(KEY_BUNDLE, id);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_state_viewpager, null);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        List<String> list = initData();
        mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerview);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        ListAdapter adapter = new ListAdapter(list);
        mRecyclerView.setAdapter(adapter);
    }

    private List initData() {
        Bundle arguments = getArguments();
        ArrayList<String> list = new ArrayList<>();
        int anInt = arguments.getInt(KEY_BUNDLE);
        for (int i = 0; i < 100; i++) {
            list.add(String.format("tyep = %s ,item position = %s", anInt, i));
        }
        return list;
    }
}
